#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__author__ = 'Liu DengFeng'

import base64
import ddddocr
import b64_images

det = ddddocr.DdddOcr(det=False,ocr=False,show_ad=False)
simple_target=True

def slide_distance(images):
    slidingImage_b64str = images.slidingImage
    backImage_b64str = images.backImage
  
    target_bytes = base64.b64decode(slidingImage_b64str)
    background_bytes = base64.b64decode(backImage_b64str)
  
    res = det.slide_match(target_bytes, background_bytes, simple_target)
  
    return res

record = {'样例总数':len(b64_images.img_list),'正确数':0,'错误数':0,'正确率':'%'}
errList = []

def test(): 
    for imgs in b64_images.img_list:
        xpos = imgs.xpos
        cal_x = slide_distance(imgs)['target'][0]

        if abs(xpos - cal_x) < 5:
            record['正确数'] += 1
        else:
            record['错误数'] += 1
            errList.append(imgs.capcode)
        
    record['正确率'] = str(round(record['正确数'] / len(b64_images.img_list) * 100, 2)) + '%'
    print('simple_target =', simple_target)
    print('')
    print('错误图片列表：', errList)
    print('')
    print('测试结果:', record)


if __name__=='__main__':
  print('-----------------------------------------------------------------------------------')
  test()
  print('-----------------------------------------------------------------------------------')